﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class KefuDAL
    {
#pragma warning disable CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        string conn = ConfigurationSettings.AppSettings["con"].ToString();
#pragma warning restore CS0618 // “ConfigurationSettings.AppSettings”已过时:“This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings”
        /// <summary>
        /// 查看客服
        /// </summary>
        /// <returns></returns>
        public DataTable shows()
        {
            SqlParameter[] sp = new SqlParameter[] { };
            string sqlstr = "select * from kefu";
            return SqlHelper.ExecuteDataSet(conn,CommandType.Text,sqlstr,sp).Tables[0];
        }
        /// <summary>
        /// 添加客服账号
        /// </summary>
        /// <param name="account"></param>
        /// <param name="nickname"></param>
        /// <param name="kf_id"></param>
        /// <returns></returns>
        public int add(string account,string nickname,string password)
        {
            SqlParameter[] sp = new SqlParameter[]{
                new SqlParameter("@account",account),
                new SqlParameter("@nickname",nickname),
                new SqlParameter("@password",password)
            };
            string sqlstr = "insert into kefu values(@account,@nickname,@password)";
            return SqlHelper.ExecuteNonQuery(conn,CommandType.Text,sqlstr,sp);
        }
        /// <summary>
        /// 删除客服
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public int del(string account)
        {
            SqlParameter[] sp = new SqlParameter[]{
                new SqlParameter("@account",account)
            };
            string sqlstr = "delete from kefu where kf_account = @account";
            return SqlHelper.ExecuteNonQuery(conn,CommandType.Text,sqlstr,sp);
        }
        /// <summary>
        /// 修改客服信息
        /// </summary>
        /// <param name="nickname"></param>
        /// <param name="password"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public int alters(string nickname, string password, string account)
        {
            SqlParameter[] sp = new SqlParameter[]{
                new SqlParameter("@nickname",nickname),
                new SqlParameter("@password",password),
                new SqlParameter("@account",account)
            };
            string sqlstr = "update kefu set kf_nick=@nickname,password=@password where kf_account=@account";
            return SqlHelper.ExecuteNonQuery(conn,CommandType.Text,sqlstr,sp);
        }
        /// <summary>
        /// 清空表table
        /// </summary>
        /// <param name="table"></param>
        public void trunc()
        {
            SqlConnection sc = new SqlConnection(conn);
            SqlCommand scs = new SqlCommand("truncate table kefu", sc);
            sc.Open();
            scs.ExecuteNonQuery();
            sc.Close();
        }
        /// <summary>
        /// 批量插入数据更新客服
        /// </summary>
        /// <param name="dt"></param>
        public int updates(DataTable dt)
        {
            return SqlHelper.SqlBulkCopyInsert(conn,"kefu",dt);
        }
    }
}
